package com.banshou.installs.ui.adapter;

import android.content.Context;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.banshou.installs.R;
import com.banshou.installs.model.dao.ResponseHisItem;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by cjq on 2018/4/22.
 * Email: stoic_yb@139.com
 * features:
 */
public class EleinfoAdapter extends CommonAdapter<ResponseHisItem> {

    public EleinfoAdapter(Context context, int layoutId, List<ResponseHisItem> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, ResponseHisItem louceInfo, int position) {
        holder.setText(R.id.tv_title,louceInfo.getLoucen().concat("楼"));
        holder.setText(R.id.tv_left,louceInfo.getLoucen());
        holder.setVisible(R.id.tv_center,louceInfo.getLoucen().contains("-"));
        holder.setText(R.id.tv_center,louceInfo.getLoucen().contains("-") ? louceInfo.getLoucen().replace("-", "B") : louceInfo.getLoucen());
        holder.setImageResource(R.id.iv_check,louceInfo.getCommon().equals("true")?R.drawable.right:R.drawable.gary);

        final TextView tv_left = holder.getView(R.id.tv_left);
        final TextView tv_center = holder.getView(R.id.tv_center);
        final LinearLayout ll_right = holder.getView(R.id.right);
        final TextView et_right = holder.getView(R.id.et_input);

        if (louceInfo.getName().equals(louceInfo.getLoucen())) {
            setEnable(1, tv_left, tv_center, ll_right, et_right);
            et_right.setText("");
            holder.setVisible(R.id.iv_cancel,true);
        } else if (louceInfo.getName().contains("B")) {
            setEnable(2, tv_left, tv_center, ll_right, et_right);
            et_right.setText("");
            holder.setVisible(R.id.iv_cancel,true);
        } else {
            setEnable(3, tv_left, tv_center, ll_right, et_right);
            et_right.setText(louceInfo.getName());
            holder.setVisible(R.id.iv_cancel,false);
        }
    }

    private void setEnable(int i, TextView tv_left, TextView tv_center, LinearLayout ll_right, TextView et_right) {
        switch (i) {
            case 1:
                tv_left.setSelected(true);
                tv_center.setSelected(false);
                ll_right.setBackgroundResource(R.drawable.floor_set_unselect);
                break;
            case 2:
                tv_left.setSelected(false);
                tv_center.setSelected(true);
                ll_right.setBackgroundResource(R.drawable.floor_set_unselect);
                break;
            case 3:
                tv_left.setSelected(false);
                tv_center.setSelected(false);
                ll_right.setBackgroundResource(R.drawable.floor_set_select);
                break;
        }
    }
}
